<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use App\Http\Controllers\Laravel\Collection\TestController;
use App\Http\Controllers\Laravel\DB\DBController;
use App\Http\Controllers\Laravel\Event\LabController;
use App\Http\Controllers\Laravel\HelpFun\FastFunController;
use App\Http\Controllers\Laravel\ORM\ModelController;
use App\Http\Controllers\Laravel\Request\HttpController;
use App\Http\Controllers\Laravel\Response\BackController;
use App\Http\Controllers\Laravel\Storage\FunController;
use App\Http\Controllers\PhpCookBook\Arr\ChangeTypeController;
use App\Http\Controllers\PhpCookBook\Arr\CheckController;
use App\Http\Controllers\PhpCookBook\Arr\StructureController;
use App\Http\Controllers\PhpCookBook\Email\SoapClientController;
use App\Http\Controllers\PhpCookBook\Globals\ServerController;
use App\Http\Controllers\PhpCookBook\Number\ExampleController;
use App\Http\Controllers\WorkProject\JbhDev\ProjectController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
});

Route::get('/string',function(){
	for($i = 0, $s = 1;$i < 10;$i ++){
		$s = lookandsay($s);
		//print "$s\n";
	}
	
	$test_str = "12232  \t1223\t  \n131\t2\t22\t232";
	print "\n".tab_unexpand($test_str);
	print "\n".$test_str;
	dd(trim("salami\n") == "salami");
	
});
Route::group([
    'prefix' => 'laravel',
    'namespace' => 'Laravel'
],function(){
    Route::group([
        'prefix' => 'cache',
        'namespace' => 'Cache'
    ],function(){
        Route::get('fun/{action}',function(\App\Http\Controllers\Laravel\Cache\FunController $index,$action){
            return $index->$action();
        });
    });
    Route::group([
        'prefix' => 'collection',
        'namespace' => 'Collection'
    ],function(){
        Route::get('test/{action}',function(TestController $index,$action){
            return $index->$action();
        });
    });
    Route::group([
        'prefix' => 'event',
        'namespace' => 'Event'
    ],function(){
        Route::get('lab/{action}',function(LabController $index,$action){
            return $index->$action();
        });
    });

    Route::group([
        'prefix' => 'helpfun',
        'namespce' => 'HelpFun'
    ],function(){
        Route::get('fast/{action}',function(FastFunController $index,$action){
            return $index->$action();
        });
    });

    Route::group([
        'prefix' => 'queue',
        'namespace'=> 'Queue'
    ],function(){
        Route::get('lab/{action}',function(\App\Http\Controllers\Laravel\Queue\LabController $index,$action){
            return $index->$action();
        });
    });
    Route::group([
        'prefix' => 'carbon',
        'namespace' => 'Carbon'
    ],function(){
        Route::get('lab/{action}',function(\App\Http\Controllers\Laravel\Carbon\LabController $index,$action){
            return $index->$action();
        });
    });
    Route::group([
        'prefix' =>'orm',
        'namespace' => 'ORM'
    ],function(){
        Route::get('model/{actioin}',function(ModelController $index,$action){
            return $index->$action();
        });
    });
    Route::group([
        'prefix' =>'db',
        'namespace' => 'DB'
    ],function(){
        Route::get('db/{actioin}',function(DBController $index,$action){
            return $index->$action();
        });
    });
    Route::group([
        'prefix' =>'storage',
        'namespace' => 'Storage'
    ],function(){
        Route::get('fun/{actioin}',function(FunController $index,$action){
            return $index->$action();
        });
    });

    Route::group([
        'prefix' =>'request',
        'namespace' => 'Request'
    ],function(){
        //Route::get('http/noExistHasError','HttpController@noExistHasError');
        //使用$index->$action() 要这样注入才能接受到参数
        Route::get('http/{action}',function(HttpController $index,$action,Request $request){
            return $index->$action($request);
        });
    });

    Route::group([
        'prefix' => 'response',
        'namespace' => 'Response'
    ],function (){
        Route::get('back/{action}',function(BackController $index,$action,Request $request){
            return $index->$action($request);
        });
    });

    Route::group([
        'prefix' =>'middleware',
        'namespace' => 'Middle'
    ],function(){
        Route::get('middle/{action}',function(\App\Http\Controllers\Laravel\Middle\LabController $index,$action,Request $request){
            return $index->$action($request);
        })->middleware('lab.after','lab.last','lab.middle','lab.before');
        //如果是普通的middle类,按参数顺序执行
        //如果是after类型的,参数考前的,越往后执行,先进后出
        //如果是before类型的(其实没有什么before类型的),按参数顺序执行,和普通的没什么区别
    });

    Route::group([
        'prefix' => 'ue',
    ],function (){
        Route::get("showBaseView",["uses" => "UEController@showBaseView"]);
        Route::post("postContent",["uses" => "UEController@postContent"]);
        Route::post("postDataForPlaceholderList",["uses" => "UEController@postDataForPlaceholderList"]);
        Route::get("testRPNotation",["uses" => "UEController@testRPNotation"]);
    });


});
Route::group([
	'prefix' => 'phpcookbook',
	'namespace' => 'PhpCookBook'
],function(){
	Route::group([
	'prefix' => 'string',
	'namespace' => 'String'
	],function(){
		Route::get('1-11-fputcsv','ExampleController@fputcsv');
		Route::get('1-28-fputcsv','ExampleController@phpOutPut');
		Route::get('1-29-fputcsv','ExampleController@obFputcsv');
		Route::get('fputcsv/{action}', function(App\Http\Controllers\PhpCookBook\String\ExampleController $index, $action){
			return $index->$action();
		});
		Route::get('30-39/{action}', function(App\Http\Controllers\PhpCookBook\String\ExampleThreeController $index, $action){
			return $index->$action();
		});
	});
	Route::group([
	    'prefix' => 'number',
        'namespace' => 'Number'
    ],function(){
	    Route::get('2-1/{action}',function(ExampleController $index,$action){
	        return $index->$action();
        });
    });

	Route::group([
	    'prefix' => 'time',
        'namespace' => 'Time'
    ],function(){
        Route::get('3-1/{action}',function(\App\Http\Controllers\PhpCookBook\Time\ExampleController $index,$action){
            return $index->$action();
        });
    }
    );

	Route::group([
	    'prefix' => 'arr',
        'namespace' => 'Arr'
    ],function(){
	    Route::get('struct/{action}',function(StructureController $index,$action){
            return $index->$action();
        });

	    Route::get('type/{action}',function(ChangeTypeController $index,$action){
	        return $index->$action();
        });

        Route::get('check/{action}',function(CheckController $index,$action){
            return $index->$action();
        });


    });

    Route::group([
        'prefix' =>'globals',
        'namespace' => 'Global'
    ],function(){
        Route::get('server/{actioin}',function(ServerController $index,$action){
            return $index->$action();
        });
    });

    Route::group([
        'prefix' =>'obj',
        'namespace' => 'Obj'
    ],function(){
        Route::get('fun/{actioin}',function(\App\Http\Controllers\PhpCookBook\Obj\FunController $index,$action){
            return $index->$action();
        });
        Route::get('self/{actioin}',function(\App\Http\Controllers\PhpCookBook\Obj\SelfController $index,$action){
            return $index->$action();
        });
    });

    Route::group([
        'prefix' =>'email',
        'namespace' => 'Email'
    ],function(){
        Route::get('soap/{actioin}',function(SoapClientController $index,$action){
            return $index->$action();
        });
    });

});




function lookandsay($s){
	$r = '';
	$m = $s[0];
	$n = 1;
	for($i = 1,$j = strlen($s);$i < $j;$i++){
		if($s[$i] == $m){
			$n++;
		} else {
			$r .= $n.$m;
			$m = $s[$i];
			$n = 1;
		}
	}
	return ($r.$n.$m);
}

//1-22
function tab_expand($text){
	//echo strstr($text,"\t");exit;
	while(strstr($text,"\t")){
		$text = preg_replace_callback('/^([^\t\n]*)(\t+)/m','tab_expand_helper',$text);
	}
	return $text;
}
function tab_expand_helper($matches){
	$tab_stop = 8;
	return $matches[1].str_repeat(' ',strlen($matches[2]) * $tab_stop - (strlen($matches[1]) % $tab_stop));
}
function tab_unexpand($text){
	$tab_stop = 4;
	$lines = explode("\n",$text);
	foreach($lines as $i => $line){
		$line = tab_expand($line);
		$chunks  = str_split($line,$tab_stop);
		$chunkCount = count($chunks);
		for($j = 0;$j < $chunkCount - 1;$j++){
			$chunks[$j] = preg_replace('/ {2,}$/',"\t",$chunks[$j]);
		}
		if($chunks[$chunkCount - 1] == str_repeat(' ',$tab_stop)){
			$chunks[$chunkCount -1] = "\t";
		}
		$lines[$i] = implode('',$chunks);
	}
	return implode("\n",$lines);
}

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::group([
    'prefix' => 'work',
    'namespace' => 'WorkProject'
],function(){
    Route::group([
        'prefix' => 'jbhdev',
        'namespace' => 'JbhDev'
    ],function(){
        Route::get('project/{action}',function(ProjectController $index,$action){
            return $index->$action();
        });
    });
});

Route::get('/event', function(){
    //Event::fire(new \App\Events\BroadcastTestEvent(3));//等测
    event(new \App\Events\BroadcastTestEvent(3));
    //return "这是要广播的";
    echo '123123';
});

Route::get('/eventPage', function(){
    return view('broadcast.test');
});